package com.mondo.financialwallet.presentation.ui.adapter;

import android.content.Context;
import android.support.annotation.Nullable;
import android.text.TextUtils;
import android.widget.ImageView;

import com.bumptech.glide.Glide;
import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;
import com.mondo.financialwallet.R;
import com.mondo.financialwallet.data.entity.FindEntity;
import com.mondo.financialwallet.presentation.model.DAppInfoModel;
import com.mondo.financialwallet.presentation.model.HotProducts;

import java.util.ArrayList;
import java.util.List;

public class SimpleDAppAdapter extends BaseQuickAdapter<DAppInfoModel, BaseViewHolder> {

    public static SimpleDAppAdapter createRecently(List<FindEntity.DataBean.RecentlyBean> apps){
        List<DAppInfoModel> appList = new ArrayList<>();
        for (FindEntity.DataBean.RecentlyBean app : apps) {
            appList.add(new DAppInfoModel(app.getName(), app.getIcon_url()));
        }

        return new SimpleDAppAdapter(R.layout.item_find_simple_app, appList);
    }

    public static SimpleDAppAdapter createHot(List<FindEntity.DataBean.HeatDappsBean> apps){
        List<DAppInfoModel> appList = new ArrayList<>();
        for (FindEntity.DataBean.HeatDappsBean app : apps) {
            appList.add(new DAppInfoModel(app.getName(), app.getIcon_url()));
        }

        return new SimpleDAppAdapter(R.layout.item_find_simple_app, appList);
    }

    public static SimpleDAppAdapter createDetails(List<DAppInfoModel> appList){
        return new SimpleDAppAdapter(R.layout.item_find_details_app, appList);
    }

    private SimpleDAppAdapter(int layoutResId, @Nullable List<DAppInfoModel> data) {
        super(layoutResId, data);
    }

    @Override
    protected void convert(BaseViewHolder helper, DAppInfoModel item) {
        Context context = helper.itemView.getContext();
        helper.setText(R.id.name_text_view, item.getName());

        String description = item.getDescription();
        if (!TextUtils.isEmpty(description)){
            helper.setText(R.id.description_text_view, description);
        }

        Glide.with(context)
                .load(item.getCover())
                .into((ImageView) helper.itemView.findViewById(R.id.cover_image_view));
    }
}
